import React, { Component, PropTypes } from 'react';

let Editor;

// react-ace 不支持服务端渲染
if (process.env.BROWSER) {
    Editor = require('./editor.jsx').default;
} else {
    Editor = require('./editor-in-server.jsx').default;
}

/**
 * 编辑器容器
 * 包含所有已打开文件
 * @class {EditorContainer}
 * @extends {React.Component}
 */
export default class EditorContainer extends Component {

    static propTypes = {
        /**
         * 当前选中项
         * @type {number|string}
         */
        selectedIndex: PropTypes.number,

        /**
         * 标签页元素
         * @type {Object[]}
         */
        items: PropTypes.array,

        /**
         * 传给子元素的属性
         * @type {Object}
         */
        childProps: PropTypes.object
    };

    render() {
        const { selectedIndex, items, childProps } = this.props;

        return (
            <div className="editor-container">
                {items.map((item, index) => (
                    <Editor key={item.path}
                        path={item.path}
                        active={selectedIndex === index} 
                        {...childProps} />
                ))}
            </div>
        );
    }
}